import matplotlib
matplotlib.use('TkAgg')

import matplotlib.pyplot as plt
import numpy as np

import pandas as pd

df = pd.read_excel('./results.xlsx')
dict_list = df.to_dict(orient='records')

tasks = df['task'].unique()
model_names = df['model'].unique()
models = {model: [] for model in model_names}

for task in tasks:
    task_data = df[df['task'] == task]
    for model in model_names:
        value = task_data[task_data['model'] == model]['f1-mean'].values
        models[model].append(value[0])



# tasks = ['ER', 'Grade', 'HER2', 'Ki67', 'pCR', 'PR']

N = len(tasks)

# models = {
#     'CRISP': [0.97, 0.94, 0.99, 0.94, 0.98, 0.97],
#     'Virchow2': [0.95, 0.95, 0.95, 0.92, 0.95, 0.94],
#     'Virchow': [0.91, 0.92, 0.87, 0.84, 0.88, 0.84],
#     'UNI': [0.91, 0.94, 0.97, 0.88, 0.87, 0.87],
#     'CONCH': [0.88, 0.85, 0.89, 0.84, 0.93, 0.88],
#     'CHIEF': [0.2, 0.86, 0.4, 0.7, 0.77, 0.1]
# }

colors = ['#5B4E9D', '#E74C9C', '#FF6B9D', '#FF8B6B', '#FFB84D', '#F4E04D']

# 计算角度
angles = np.linspace(0, 2 * np.pi, N, endpoint=False).tolist()
angles += angles[:1]

fig, ax = plt.subplots(figsize=(7, 7), subplot_kw=dict(projection='polar'))

for method_index, (method_name, values) in enumerate(models.items()):
    values_plot = values + values[:1]
    method_color = colors[method_index]
    ax.plot(angles, values_plot, 'o-', linewidth=2.5,
            label=method_name, color=colors[method_index],
            markersize=6, alpha=0.8)
    ax.fill(angles, values_plot, alpha=0.12, color=method_color)
    for angle, value in zip(angles[:-1], values):
        ax.text(angle, value, f'{value:.2f}',
                ha='center', va='bottom',
                fontsize=7, color=method_color,
                weight='bold', alpha=0.9)

ax.set_xticks(angles[:-1])
ax.set_xticklabels(tasks, size=10, weight='bold')

ax.set_ylim(0, 0.8)
ax.set_yticks([0, 0.2, 0.4, 0.6])
ax.set_yticklabels([])

ax.grid(True, linestyle='-', alpha=0.3, linewidth=1)
# ax.spines['polar'].set_visible(False)


legend = ax.legend(fontsize=7, frameon=False)

plt.tight_layout()
# plt.show()
plt.savefig("png_radar.png")
